<template>
  <div class="app-container">
    <el-row>
      <el-col :span="4" style="margin-left: -24px; margin-top: -12px">
        <MainType :typeCode="typeCode" @getNode="getNode"></MainType>
      </el-col>
      <el-col :span="20">
        <el-form
          style="margin-left: 20px"
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          v-show="showSearch"
          label-width="68px"
        >
          <el-form-item label="文件名称" prop="fileName">
            <el-input
              v-model="queryParams.fileName"
              placeholder="请输入文件名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="文件编号" prop="documentNumber">
            <el-input
              v-model="queryParams.documentNumber"
              placeholder="请输入文件编号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              style="margin-left: 30px"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              >新增</el-button
            >
          </el-col>
          <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="getList"
          ></right-toolbar>
        </el-row>
        <div style="width: 100%;height: 90vh;overflow:auto; margin-bottom: 30%;padding-bottom: 18%;position: relative;">
        <el-table
          style="margin-left: 30px"
          height="400px"
          :row-style="{ height: '30px' }"
          border
          :cell-style="{ padding: '0px' }"
          v-loading="loading"
          :data="documentList"
        >
          <el-table-column
            label="序号"
            align="center"
            type="index"
            :index="indexMethod"
          />
          <el-table-column
            label="排序"
            align="center"
            prop="orderNum"
            width="50px"
          />
          <el-table-column
            label="文件柜名称"
            align="center"
            prop="mainName"
            :show-overflow-tooltip="true"
            width="143"
          />
          <el-table-column
            label="文件名称"
            align="center"
            prop="fileName"
            :show-overflow-tooltip="true"
            width="173"
          >
            <template slot-scope="scope">
              <!-- 使用按钮作为可点击元素，并绑定点击事件 -->
              <el-button
                size="small"
                v-if="scope.row.fileUrl != null && scope.row.fileUrl != ''"
                @click="queryUploadFile(scope.row, scope.$index + 1)"
                type="text"
              >
                {{ scope.row.fileName }}
              </el-button>
              <!-- <el-button size="small" v-else type="text">无附件</el-button> -->
              <span v-else>{{ scope.row.fileName }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="文件编号"
            align="center"
            width="100"
            prop="documentNumber"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="版本"
            align="center"
            prop="version"
            width="70"
          />
          <!-- <el-table-column label="生效时间" align="center" prop="effectiveTime" width="100" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.effectiveTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column> -->
          <el-table-column label="状态" align="center" prop="state">
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.file_status"
                :value="scope.row.state"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="建立人"
            align="center"
            prop="establishedName"
            width="150"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="建立时间"
            align="center"
            prop="establishmentTime"
            width="100"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span>{{
                parseTime(scope.row.establishmentTime, "{y}-{m}-{d}")
              }}</span>
            </template>
          </el-table-column>

          <el-table-column
            label="管理部门（更新人）"
            align="center"
            prop="newValue"
            width="140"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="最新变更时间"
            align="center"
            prop="changeTime"
            width="130"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span>{{
                parseTime(scope.row.changeTime, "{y}-{m}-{d} {hh}:{ss}")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="变更人"
            align="center"
            prop="changedName"
            :show-overflow-tooltip="true"
          />
          <!-- <el-table-column label="附件" align="center" prop="fileUrl" width="100" height="220">
              <template slot-scope="scope" >
                <div class="block" @click="handlePictureCardPreviewPdf(scope.row.fileUrl)" >
                  <pdf :src="scope.row.fileUrl"></pdf>
                </div>
              </template>
            </el-table-column> -->
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            width="140"
            fixed="right"
          >
            <template
              slot-scope="scope"
              v-if="
                userId == '1' ||
                userId == '2' ||
                scope.row.establishedId == userId
              "
            >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-document-add"
                @click="handleqx(scope.row)"
                title="权限设置"
              ></el-button>
              <!-- <el-button size="mini" icon="el-icon-download" v-if="scope.row.fjFileName !=null" @click="handleDownload(scope.row.fileUrl,scope.row.fjFileName)" type="text">
                    下载
                </el-button> -->
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                title="修改"
              ></el-button>
              <!-- <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                  >删除</el-button> -->
            </template>
          </el-table-column>
        </el-table>
        <pagination
          style="margin-left: 30px"
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
        </div>
      </el-col>
    </el-row>
    <!-- 查看附件 -->
    <el-dialog
      title="查看附件"
      :visible.sync="openFileList"
      width="600px"
      append-to-body
    >
      <el-table
        :data="fileList"
        height="300px"
        :row-style="{ height: '30px' }"
        border
        :cell-style="{ padding: '0px' }"
      >
        <el-table-column label="序号" type="index" :index="indexMethodFile" />
        <el-table-column
          label="文件名称"
          align="center"
          prop="fileName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          fixed="right"
          width="120"
        >
          <template slot-scope="scope">
            <el-button
              v-if="
                scope.row.fileType != '.word' &&
                scope.row.fileType != '.xlsx' &&
                scope.row.fileType != '.doc'
              "
              size="mini"
              type="text"
              icon="el-icon-view"
              @click.stop="handleView(scope.row)"
              title="查看"
            ></el-button>

            <el-button
              size="mini"
              type="text"
              icon="el-icon-download"
              @click="handleDownload(scope.row.url, scope.row.fileName)"
              title="下载"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <!-- 权限设置对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="qxopen"
      width="700px"
      append-to-body
    >
      <el-form ref="qxform" :model="qxform" :rules="qxrules" label-width="95px">
        <el-form-item label="文件柜名称" prop="cabinetId">
          <treeselect
            v-model="form.cabinetId"
            :options="optionData"
            placeholder="请选择文件柜"
            style="width: 312rem"
          />
        </el-form-item>
        <el-form-item label="文件名称" prop="fileName">
          <el-input
            v-model="qxform.fileName"
            placeholder="请输入文件名称"
            disabled="true"
            style="width: 455px"
          />
        </el-form-item>
        <el-col :span="1.5">
          <span style="font-size: 14px; margin-left: 250px">权限用户</span
          >&nbsp;&nbsp;&nbsp;&nbsp;
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="selectOpen(2)"
            title="用户选择"
            style="text-align: center; margin-bottom: 15px"
          ></el-button>
        </el-col>
        <!-- <el-form-item label="读写权限" prop="readWritePermission">
          <el-input v-model="qxform.readWritePermission" type="textarea" placeholder="请选择" @focus="selectOpen(2)" rows="5" style="width:370px" readonly="true"/>
          <el-button type="primary" @click="selectOpen(2)" style="margin:0px 10px 80px 10px;">选 择</el-button>
          <el-button @click="canceldx" style="margin:0px 10px 100px 10px;">清 空</el-button>
        </el-form-item> -->
        <el-table
          :row-style="{ height: '30px' }"
          border
          :cell-style="{ padding: '0px' }"
          height="280"
          v-loading="loading"
          :data="permissionList"
          :visible.sync="openPermission"
        >
          <!-- <el-row style="margin: 25px 100px 25px 550px;">权限用户1</el-row> -->
          <el-table-column
            label="序号"
            type="index"
            :index="indexMethodPermission"
            align="center"
            width="50"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="用户名称"
            align="center"
            width="219"
            prop="permissionUserName"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="所属部门"
            align="center"
            prop="deptName"
            width="150"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="创建人"
            align="center"
            prop="creationName"
            width="100"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="创建时间"
            align="center"
            prop="creationTime"
            width="90"
          >
            <template slot-scope="scope">
              <span>{{
                parseTime(scope.row.creationTime, "{y}-{m}-{d}")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="50"
            fixed="right"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <table-operation-buttons
                :has-delete="true"
                delete-text="删除该条目"
                title="删除"
                @delete="handleDeletePermission(scope.row)"
              />
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="Permissiontotal > 0"
          :total="Permissiontotal"
          :page.sync="queryParamsPermission.pageNum"
          :limit.sync="queryParamsPermission.pageSize"
          @pagination="getPermissionList"
        />
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="submitFormqx"  size="mini">确 定</el-button> -->
        <el-button @click="cancelqx" size="mini">关 闭</el-button>
      </div>
    </el-dialog>
    <!-- <select-user ref="select" :fjgFiName="fjgFiName" :wName="wName" :showType="show" @selectUser="selectUser"></select-user> -->
    <!-- 添加或修改内部文件对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-tabs v-model="activeName">
        <el-tab-pane label="文件信息" name="first">
          <el-form
            ref="form"
            :model="form"
            :rules="rules"
            label-width="100px"
            :inline="true"
          >
            <el-row>
              <el-col>
                <el-form-item label="显示排序" prop="orderNum">
                  <el-input-number
                    style="width: 250px"
                    v-model="form.orderNum"
                    controls-position="right"
                    :min="0"
                  />
                </el-form-item>
                <el-form-item label="文件柜名称" prop="cabinetId">
                  <treeselect
                    v-model="form.cabinetId"
                    :options="optionData"
                    placeholder="请选择文件柜"
                    style="width: 312rem"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="文件名称" prop="fileName">
                  <el-input
                    v-model="form.fileName"
                    placeholder="请输入文件名称"
                    style="width: 250px"
                    maxlength="50"
                  />
                </el-form-item>
                <el-form-item label="文件编号" prop="documentNumber">
                  <el-input
                    v-model="form.documentNumber"
                    placeholder="请输入文件编号"
                    style="width: 250px"
                    maxlength="30"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="版本" prop="version">
                  <el-input
                    v-model="form.version"
                    placeholder="请输入版本"
                    style="width: 250px"
                    maxlength="30"
                  />
                </el-form-item>
                <el-form-item label="状态" prop="state">
                  <el-select
                    v-model="form.state"
                    style="width: 250px"
                    placeholder="请选择状态"
                  >
                    <el-option
                      v-for="dict in dict.type.file_status"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <!-- <el-row>
              <el-col>
                <el-form-item label="生效时间" prop="effectiveTime">
                  <el-date-picker clearable
                    v-model="form.effectiveTime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="请选择生效时间" style="width:250px">
                  </el-date-picker>
                </el-form-item>

              </el-col>
            </el-row> -->
            <el-row>
              <el-col>
                <el-form-item label="建立人" prop="establishedName">
                  <el-input
                    v-model="form.establishedName"
                    style="width: 250px"
                    :disabled="true"
                  />
                </el-form-item>
                <el-form-item label="建立时间" prop="establishmentTime">
                  <el-input
                    v-model="form.establishmentTime"
                    style="width: 250px"
                    :disabled="true"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row v-show="changeShow">
              <el-col>
                <el-form-item label="管理部门" prop="managementDepartment">
                  <el-input
                    v-model="form.managementDepartment"
                    style="width: 250px"
                    :disabled="true"
                  />
                </el-form-item>
                <el-form-item label="变更人" prop="changedName">
                  <el-input
                    v-model="form.changedName"
                    style="width: 250px"
                    :disabled="true"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row v-show="changeShow">
              <el-col>
                <el-form-item label="更新人" prop="updatedName">
                  <el-input
                    v-model="form.updatedName"
                    style="width: 250px"
                    :disabled="true"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="附件">
                  <file-view
                    :type="fjFileType"
                    :key="refreshKey"
                    :businessId="businessId"
                    :businessCode="businessCode"
                    @change="getFile"
                  ></file-view>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <div style="text-align: right">
            <el-button type="primary" sizi="mini" @click="submitForm"
              >保 存</el-button
            >
            <el-button @click="cancelNew">关 闭</el-button>
          </div>
        </el-tab-pane>
        <el-tab-pane label="变更记录" name="second" :disabled="isShowTab">
          <el-table
            :data="recordList"
            :row-style="{ height: '30px' }"
            border
            :cell-style="{ padding: '0px' }"
            height="280"
          >
            <el-table-column
              label="序号"
              type="index"
              align="center"
              :index="indexMethodRecord"
            />
            <el-table-column label="变更人" align="center" prop="changedName" />
            <el-table-column label="变更时间" align="center" prop="changeTime">
              <template slot-scope="scope">
                <span>{{
                  parseTime(scope.row.changeTime, "{y}-{m}-{d}")
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="变更内容"
              align="center"
              prop="changeContent"
              width="400"
              :show-overflow-tooltip="true"
            />
          </el-table>
          <pagination
            v-show="totalRecord > 0"
            :total="totalRecord"
            :page.sync="queryParamsRecord.pageNum"
            :limit.sync="queryParamsRecord.pageSize"
            @pagination="getRecordList"
          />
          <div style="text-align: right; margin-top: 100px">
            <el-button @click="cancelNew">关 闭</el-button>
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>
    <!-- 图片预览 -->
    <el-dialog :visible.sync="dialogVisible" append-to-body>
      <img width="100%" :src="dialogImageUrl" alt="" />
    </el-dialog>
    <!-- pdf预览 -->
    <el-dialog :visible.sync="dialogVisiblePdf" append-to-body>
      <pdf
        v-for="item in pageTotal"
        :src="pdfUrl"
        :key="item"
        :page="item"
      ></pdf>
    </el-dialog>

    <select-user
      ref="select"
      :type="userType"
      :sign="sign"
      @ok="selectUser"
    ></select-user>
  </div>
</template>

<script>
import {
  listFileTreeInternal,
  listInternal,
  getInternal,
  delInternal,
  addInternal,
  updateInternal,
} from "@/api/file/internal";
import FileTree from "@/components/File/index";
import { listTypeOther } from "@/api/maintype/type";
import Treeselect from "@riophae/vue-treeselect";
import MainType from "@/components/MainType/indexNew";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {
  listChange,
  getChange,
  delChange,
  addChange,
  updateChange,
} from "@/api/file/change";
import { download } from "@/utils/request";
import FileView from "@/components/FileView/index";
import { id } from "@/api/system/UUID";
import pdf from "vue-pdf";
import { queryFile, fileRemove } from "@/api/system/file";
import SelectUser from "../../system/role/selectUser.vue";
import {
  listPermission,
  getPermission,
  delPermission,
  addPermission,
  updatePermission,
} from "@/api/file/permission";
import TableOperationButtons from "@/components/TableOperationButtons/index";
export default {
  name: "Internal",
  dicts: ["file_status"],
  components: { MainType, Treeselect, FileView, pdf, SelectUser, TableOperationButtons },
  data() {
    return {
      classId: "",
      typeCode: "enterprise",
      Permissiontotal: 0,
      openPermission: true,
      sign: "1",
      userType: "0",
      refreshKey: 0,
      openFileList: false,
      permissionList: [],
      show: "",
      fjgFiName: "",
      wName: [],
      formClass: {},
      qxopen: false,
      //附件参数
      fjFileType: 0,
      businessId: null,
      businessCode: "internal",
      guId: "",
      userId: "",
      changeShow: false,
      fileType: "3",
      isShowTab: true,
      //选显卡默认选中
      activeName: "first",
      optionData: null,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 外部文件表格数据
      documentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      totalRecord: 0,
      recordList: [],
      //pdf预览
      dialogImageUrl: "",
      dialogImageUrlPdf: "",
      pageTotal: null,
      dialogVisible: false,
      dialogVisiblePdf: false,
      queryParamsRecord: {
        pageNum: 1,
        pageSize: 15,
        internalId: null,
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 15,
        fileName: null,
        internalId: null,
        cabinetId: null,
        cabinetName: null,
        documentNumber: null,
        establishmentTime: null,
        establishedId: null,
        establishedName: null,
        effectiveTime: null,
        version: null,
        state: null,
        managementDepartment: null,
        changedId: null,
        changedName: null,
        operateTime: null,
        operateId: null,
        operateName: null,
        departmentId: null,
        departmentName: null,
        organizationId: null,
        organizationName: null,
        creationId: null,
        creationName: null,
        creationTime: null,
        readWritePermissionId: null,
        readWritePermission: null,
        belongTo: null,
      },
      userid: [],
      // 表单参数
      form: {},
      qxform: {
        readWritePermissionId: null,
        readWritePermission: null,
      },
      qxrules: {
        readWritePermission: [
          { required: true, message: "读写权限不能为空", trigger: "change" },
        ],
      },
      fileList: [],
      itemFileTree: Date.now(),
      // 查询参数
      queryParamsFile: {
        pageNum: 1,
        pageSize: 15,
        fileName: null,
      },
      queryParamsPermission: {
        pageNum: 1,
        pageSize: 5,
        internalId: null,
      },
      internalId: "",
      // 表单校验
      rules: {
        fileName: [
          { required: true, message: "文件名称不能为空", trigger: "blur" },
          { max: 50, message: "文件名称长度不能超过50", trigger: "blur" },
        ],
        documentNumber: [
          { required: true, message: "文件编号不能为空", trigger: "blur" },
          { max: 50, message: "文件编号不能超过50字", trigger: "blur" },
        ],
        cabinetId: [
          { required: true, message: "文件柜名称不能为空", trigger: "change" },
        ],
        effectiveTime: [
          { required: true, message: "生效时间不能为空", trigger: "change" },
        ],
        state: [{ required: true, message: "状态不能为空", trigger: "change" }],
        version: [
          { required: true, message: "版本不能为空", trigger: "blur" },
          //{ max: 50, message: '文件编号不能超过50字', trigger: 'blur' }
        ],
      },
    };
  },
  created() {
    this.getList();
    this.listType();
    this.listFileTreeInternal();
    this.getRecordList();
  },
  methods: {
    listType() {
      listTypeOther({ typeCode: "enterprise" }).then(res => {
        this.optionData = res.data;
      });
    },
    getNode(data, node, obj) {
      this.queryParams.cabinetId = data.id;
      this.classId = data.id;
      this.getList();
    },
    getFile(data) {
      //console.log(JSON.stringify(data))
    },
    //序号展示
    indexMethodFile(index) {
      return (
        (this.queryParamsFile.pageNum - 1) * this.queryParamsFile.pageSize +
        index +
        1
      );
    },
    //文件预览
    handleView(row) {
      if (row.url != null && row.url != "" && row.url.indexOf(".pdf") !== -1) {
        this.handlePictureCardPreviewPdf(row.url);
      } else {
        this.handlePictureCardPreview(row.url);
      }
    },
    handlePictureCardPreview(url) {
      this.dialogImageUrl = url;
      this.dialogVisible = true;
    },
    //查询文件
    queryUploadFile(row) {
      queryFile(row.internalId, "internal").then(response => {
        this.fileList = response.data;
        this.openFileList = true;
        console.log(this.fileList);
      });
    },
    //选择用户
    selectUser(userIds, userNames, deptIds, deptNames) {
      //this.userid = userIds.join(',');
      //alert(userIds)
      for (let i = 0; i < userIds.length; i++) {
        const Permission = {
          internalId: this.internalId.toString(),
          permissionUserId: userIds[i].toString(),
          permissionUserName: userNames[i].toString(),
          deptId: deptIds[i].toString(),
          deptName: deptNames[i].toString(),
        };
        addPermission(Permission).then(response => {
          this.getPermissionList();
        });
      }
      this.$modal.msgSuccess("添加成功");
      // this.$set(this.qxform, 'readWritePermission', userNames.join(','))//读写
      // this.$set(this.qxform, 'readWritePermissionId', userIds.join(','))
    },

    /** 删除按钮操作 */
    handleDeletePermission(row) {
      this.$modal
        .confirm(
          '是否确认删除用户名称为"' + row.permissionUserName + '"的数据项？'
        )
        .then(function () {
          return delPermission(row.permissionId);
        })
        .then(() => {
          this.getPermissionList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },

    //用户选择
    selectOpen(type) {
      // this.wName=[];
      // if(this.qxform.readWritePermission!=null||this.qxform.readWritePermission!=""){
      //   this.wName = this.qxform.readWritePermissionId;//读写
      // }

      this.show = type;
      this.$refs.select.show();
    },
    /** 权限设置按钮操作 */
    handleqx(row) {
      this.qxreset();
      //this.openPermission=true;
      this.internalId = row.internalId;
      //const internalId = row.internalId || this.ids
      getInternal(row.internalId).then(response => {
        //this.fjgFiName = row.internalId;
        this.qxform = response.data;
        this.qxopen = true;
        this.title = "权限设置";
      });
      this.getPermissionList();
    },
    // /** 权限设置提交按钮 */
    // submitFormqx() {
    //   console.log(this.qxform)
    //   this.$refs["qxform"].validate(valid => {
    //     if (valid) {
    //       this.form.operateName="2"
    //       updateInternal(this.qxform).then(response => {
    //           this.$modal.msgSuccess("保存成功");
    //           this.qxopen = false;
    //           this.getList();
    //           this.itemFileTree = Date.now()
    //       });

    //     }
    //   });
    // },

    // 取消按钮
    cancelqx() {
      this.qxopen = false;
      this.qxreset();
    },
    getPermissionList() {
      this.loading = true;
      this.queryParamsPermission.internalId = this.internalId;
      listPermission(this.queryParamsPermission)
        .then(response => {
          this.permissionList = response.rows;
          this.Permissiontotal = response.total;
          this.loading = false;
        })
        .catch(function (error) {
          alert("权限用户查询错误,请联系管理员!");
        });
    },
    /** 查询内部文件列表 */
    getList() {
      this.loading = true;
      //this.queryParams.internalId = this.$store.state.user.info.userId
      this.userId = this.$store.state.user.info.userId;
      // if(this.$store.state.user.info.userId!=1&&this.$store.state.user.info.userId!=2){
      //   this.queryParams.internalId = this.userId
      //   //this.queryParams.readWritePermissionId = this.userId
      // }
      listInternal(this.queryParams)
        .then(response => {
          // let cIndex;
          // if(response.total>0){
          //   if(this.$store.state.user.info.userId!=1){
          //     for(let index = 0; index<=response.rows.length;index++) {
          //       if(cIndex==0){
          //         index=0
          //       }
          //    //const index1 = this.documentList.findIndex(item => item.readOnly === null&&item.readWrtie===null)
          //    //如果没有权限则屏蔽该条数据
          //       if(response.rows[index].readOnly ==null&&response.rows[index].readWrtie==null) {
          //         cIndex=0;
          //         response.rows.splice(index,1)
          //       }else{
          //         cIndex=1;
          //       }
          //     }
          //   }
          // }

          this.documentList = response.rows;
          this.total = response.total;
          this.loading = false;
        })
        .catch(function (error) {
          alert("系统错误,请联系管理员!");
        });
    },
    //pdf预览
    handlePictureCardPreviewPdf(url) {
      this.pdfUrl = pdf.createLoadingTask(url);
      // 获取页码
      this.pdfUrl.promise
        .then(pdf => (this.pageTotal = pdf.numPages))
        .catch(error => {});
      this.dialogImageUrlPdf = url;
      this.dialogVisiblePdf = true;
    },
    //下载
    handleDownload(fileUrl, fileName) {
      let params = {
        resource: fileUrl,
      };
      download("/common/download/resource", params, fileName);
    },
    /** 查询变更记录列表 */
    getRecordList() {
      this.loading = true;
      listChange(this.queryParamsRecord).then(response => {
        this.recordList = response.rows;
        this.totalRecord = response.total;
      });
    },
    //权限设置序号展示
    indexMethodPermission(index) {
      return (
        (this.queryParamsPermission.pageNum - 1) *
          this.queryParamsPermission.pageSize +
        index +
        1
      );
    },
    //变更记录序号展示
    indexMethodRecord(index) {
      return (
        (this.queryParamsRecord.pageNum - 1) * this.queryParamsRecord.pageSize +
        index +
        1
      );
    },
    //内部文件序号展示
    indexMethod(index) {
      return (
        (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1
      );
    },
    //禁用父节点
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.label,
        isDisabled:
          node.parentId == "00000000-0000-0000-0000-000000000000"
            ? true
            : false,
        children: node.children,
      };
    },
    // //树点击事件
    // getNode(data, node, obj) {
    //   this.reset();
    //   if (data.id == "947cc995-011c-4577-81cc-8478ce3bab4b") {
    //     this.queryParams.cabinetId = null;
    //   } else {
    //     this.queryParams.cabinetId = data.id;
    //   }

    //   this.getList();
    // },
    // //加载文件柜树
    // listFileTreeInternal() {
    //   listFileTreeInternal().then(res => {
    //     console.log(res.data);
    //     this.optionData = res.data;
    //   });
    // },

    // 取消按钮
    cancelNew() {
      this.open = false;
      this.reset();
      this.getList();
      // this.getRecordList();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      this.getList();
      // this.getRecordList();
    },
    // 表单重置
    reset() {
      this.form = {
        internalId: null,
        fileName: null,
        cabinetId: null,
        cabinetName: null,
        documentNumber: null,
        establishmentTime: null,
        establishedId: null,
        establishedName: null,
        effectiveTime: null,
        version: null,
        state: null,
        managementDepartment: null,
        changedId: null,
        changedName: null,
        updatedId: null,
        updatedNmae: null,
        operateTime: null,
        operateId: null,
        operateName: null,
        departmentId: null,
        departmentName: null,
        organizationId: null,
        organizationName: null,
        creationId: null,
        creationName: null,
        creationTime: null,
        belongTo: null,
      };
      this.resetForm("form");
    },
    qxreset() {
      this.qxform = {
        readWritePermission: null,
        readWritePermissionId: null,
      };
      this.resetForm("qxform");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // // 多选框选中数据
    // handleSelectionChange(selection) {
    //   this.ids = selection.map(item => item.internalId)
    //   this.single = selection.length!==1
    //   this.multiple = !selection.length
    // },

    guid() {
      function S4() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
      }
      return (
        S4() +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        S4() +
        S4()
      );
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.listType();
      // this.guId ="";
      // this.businessId="";
      //this.getRecordList();
      this.refreshKey++;
      this.businessId = this.guid();
      this.fjFileType = 0;
      this.form.orderNum = 0;
      this.changeShow = false;
      this.isShowTab = true;
      (this.activeName = "first"),
        (this.form.establishedName = this.$store.state.user.name);
      console.log(this.classId,"this.classId")
      if (this.classId == null || this.classId == ""){
        this.form.cabinetId=null;
      }else {
        this.form.cabinetId = this.classId;
      }
      this.form.establishedId = this.$store.state.user.info.userId;
      this.form.establishmentTime = this.parseTime(new Date(), "{y}-{m}-{d}");
      // if (this.queryParams.cabinetId != null) {
      //   this.form.cabinetId = this.queryParams.cabinetId;
      // }
      this.open = true;
      this.title = "添加内部文件";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.fjFileType = 1;
      (this.activeName = "first"), (this.changeShow = true);
      this.refreshKey++;
      const internalId = row.internalId || this.ids;
      this.businessId = row.internalId;
      this.queryParamsRecord.internalId = row.internalId;
      listChange(this.queryParamsRecord).then(response => {
        if (response.total > 0) {
          this.isShowTab = false;
          this.recordList = response.rows;
          this.totalRecord = response.total;
        } else {
          this.isShowTab = true;
        }
      });
      getInternal(internalId).then(response => {
        this.form = response.data;
        this.form.changedName = this.$store.state.user.name; //变更人
        this.form.changedId = this.$store.state.user.info.userId; //变更人id
        this.form.updatedName = this.$store.state.user.name; //更新人
        this.form.updatedId = this.$store.state.user.info.userId; //更新人id
        this.form.managementDepartment = this.$store.state.user.info.deptName; //管理部门
        this.open = true;
        this.title = "修改内部文件";
        //this.getRecordList();
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.internalId != null) {
            this.form.operateName = "1";
            updateInternal(this.form).then(response => {
              this.$modal.msgSuccess("变更成功");
              this.open = false;
              this.getList();
              this.itemFileTree = Date.now();
              this.refreshKey++;
              //this.getId()
            });
          } else {
            this.form.internalId = this.businessId;
            addInternal(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
              this.itemFileTree = Date.now();
              this.refreshKey++;
              //this.getId()
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const internalIds = row.internalId || this.ids;
      this.$modal
        .confirm('是否确认删除内部文件名称为"' + row.fileName + '"的数据项？')
        .then(function () {
          return delInternal(internalIds);
        })
        .then(() => {
          this.itemFileTree = Date.now();
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "file/document/export",
        {
          ...this.queryParams,
        },
        `document_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style scoped></style>
